package com.atguigu.lease.web.config;

import com.atguigu.lease.web.converter.String2BaseEnumConverterFactory;
import com.atguigu.lease.web.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 51560
 * @project lease
 * @title webmvc配置类
 * @package com.atguigu.lease.web.config
 * @since 2025/5/9 9:46
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private String2BaseEnumConverterFactory string2BaseEnumConverterFactory;

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        // 添加converter
        // registry.addConverter(string2ItemTypeConverter);
        registry.addConverterFactory(string2BaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login/**");
    }
}
